package com.lm.timewheel.example;

import com.lm.timewheel.ele.TimeWheel;

public class TimeWheelExample {
    public static void main(String[] args) throws InterruptedException {
        TimeWheel timeWheel = new TimeWheel(10, 1000); // 10 个槽，每个槽间隔 1 秒

        timeWheel.addTask(() -> System.out.println("Task 1 executed!"), 3000);
        timeWheel.addTask(() -> System.out.println("Task 2 executed!"), 4000);
        timeWheel.addTask(() -> System.out.println("Task 3 executed!"), 300);
        timeWheel.addTask(() -> System.out.println("Task 4 executed!"), 5000);
        timeWheel.addTask(() -> System.out.println("Task 5 executed!"), 7888);
        timeWheel.addTask(() -> System.out.println("Task 6 executed!"), 6000);

        timeWheel.addTask(() -> System.out.println("Task 7 executed!"), 5822);
        timeWheel.addTask(() -> System.out.println("Task 8 executed!"), 7511);
        timeWheel.addTask(() -> System.out.println("Task 9 executed!"), 7924);
        timeWheel.addTask(() -> System.out.println("Task 10 executed!"), 78);
        timeWheel.addTask(() -> System.out.println("Task 11 executed!"), 5000);

        while (true) {
            timeWheel.tick();
            Thread.sleep(1000); // 每秒执行一次 tick
        }
    }
}
